package com.core.zyyz.pcmc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.core.zyyz.pcmc.domain.PcmcDict;
import com.core.zyyz.pcmc.service.PcmcDictService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 系统字典Controller
 *
 * @author core
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/pcmc/dict")
public class PcmcDictController extends BaseController
{
    @Autowired
    private PcmcDictService pcmcDictService;

    /**
     * 查询系统字典列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dict:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcmcDict pcmcDict)
    {
        startPage();
        List<PcmcDict> list = pcmcDictService.selectPcmcDictList(pcmcDict);
        return getDataTable(list);
    }


    /**
     * 查询系统字典列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dict:dictInfo')")
    @GetMapping("/dictInfo")
    public TableDataInfo dictInfo(PcmcDict pcmcDict)
    {
        startPage();
        List<PcmcDict> list = pcmcDictService.selectPcmcDictInfoList(pcmcDict);
        return getDataTable(list);
    }



    /**
     * 导出系统字典列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dict:export')")
    @Log(title = "系统字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcmcDict pcmcDict)
    {
        List<PcmcDict> list = pcmcDictService.selectPcmcDictList(pcmcDict);
        ExcelUtil<PcmcDict> util = new ExcelUtil<PcmcDict>(PcmcDict.class);
        util.exportExcel(response, list, "系统字典数据");
    }

    /**
     * 获取系统字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dict:query')")
    @GetMapping(value = "/{appCode}")
    public AjaxResult getInfo(@PathVariable("appCode") String appCode)
    {
        return success(pcmcDictService.selectPcmcDictByAppCode(appCode));
    }

    /**
     * 新增系统字典
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dict:add')")
    @Log(title = "系统字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcmcDict pcmcDict)
    {
        return toAjax(pcmcDictService.insertPcmcDict(pcmcDict));
    }

    /**
     * 修改系统字典
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dict:edit')")
    @Log(title = "系统字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcmcDict pcmcDict)
    {
        return toAjax(pcmcDictService.updatePcmcDict(pcmcDict));
    }

    /**
     * 删除系统字典
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dict:remove')")
    @Log(title = "系统字典", businessType = BusinessType.DELETE)
    @DeleteMapping("/{appCodes}")
    public AjaxResult remove(@PathVariable String[] appCodes)
    {
        return toAjax(pcmcDictService.deletePcmcDictByAppCodes(appCodes));
    }
}
